import { defineStore } from "pinia";
import { CloseConfigState, State } from "./type";

export const useConfigStore = defineStore("config", {
  state: (): State => ({
    title: "DeskTool",
    date: new Date(),
    theme: "light",
    closeType: "close",
    closeTypeTip: false,
    //
  }),
  getters: {
    //
  },
  actions: {
    toggleTheme(dark: boolean) {
      if (dark) {
        this.theme = "dark";
        document.documentElement.classList.add("dark");
      } else {
        this.theme = "light";
        document.documentElement.classList.remove("dark");
      }
    },
    /**
     * 设置关闭方式
     * @param config
     * type:关闭方式
     * tip:是否显示关闭提示
     */
    setCloseConfig(config: CloseConfigState) {
      this.closeType = config.type;
      this.closeTypeTip = config.tip;
    },
    //
  },
});
